using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AutoGear.BLL;
using ECommerce.Library.Web;

public partial class pre_checkout : SitePublicBasePage
{
    public String SupplierId
    {
        get
        {
            try
            {

                return Page.RouteData.Values["partnerId"].ToString();
            }
            catch
            {
                return string.Empty;
            }
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ContentPlaceHolder ph = (ContentPlaceHolder)this.Master.Master.FindControl("cphMiddleContent");

            Literal litPageTitle = (Literal)ph.FindControl("litPageTitle");
            Literal litCurrentPage = (Literal)ph.FindControl("litCurrentPage");

            if (litPageTitle != null)
            {
                litCurrentPage.Text = litPageTitle.Text = "Pre Checkout";

            }

            CheckoutStepsValidate();
        }
    }

    private void CheckoutStepsValidate()
    {
        ShoppingCart cart = AutoGearSessionManager.ShoppingCart;
        if (cart == null || (cart.CartItems.Count <= 0 && cart.GiftItems.Count <= 0))
            Response.Redirect(AutoGear.BLL.CustomSiteMap.ShoppingCart);

        if (AutoGearSessionManager.CheckoutSteps < CheckoutSteps.ShoppingCart)
        {
            Response.Redirect(AutoGear.BLL.CustomSiteMap.ShoppingCart);
        }     
            
    }

    protected void Signin_Click(object sender, EventArgs e)
    {
        AutoGearSessionManager.CheckoutSteps = CheckoutSteps.PreCheckout;
        if (AutoGearSessionManager.ShoppingCart.MultipleShipAdd!=null)
            SessionManager.ReturnUrl = SiteGlobals.BaseUrl + "order-summary-multiple.aspx";
        else
            SessionManager.ReturnUrl = AutoGear.BLL.CustomSiteMap.OrderSummary;

        String redirectUrl = string.IsNullOrEmpty(SupplierId) ? AutoGear.BLL.CustomSiteMap.Login : "~/partner/" + SupplierId + "/login.aspx";
        Response.Redirect(redirectUrl);
        
    }

    protected void Checkout_Click(object sender, EventArgs e)
    {
        AutoGearSessionManager.CheckoutSteps = CheckoutSteps.PreCheckout;
        //Response.Redirect(AutoGear.BLL.CustomSiteMap.OrderSummary);
        if (AutoGearSessionManager.ShoppingCart.MultipleShipAdd != null)
            Response.Redirect("~/order-summary-multiple.aspx");
        else
        {
            String redirectUrl = string.IsNullOrEmpty(SupplierId) ? AutoGear.BLL.CustomSiteMap.OrderSummary : "~/partner/" + SupplierId + "/order-summary.aspx";
            Response.Redirect(redirectUrl);
        }
    }
}
